package com.swm.util1;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.swm.mapper.StockMapper;
import com.swm.pojo.Data;
import com.swm.pojo.Stock;
import com.swm.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import static com.swm.util1.API.getBDWebData;
import static com.swm.util1.ConditionUtil.*;


/**
 * @author 师文明
 * @data 2024/12/23 下午3:11
 **/
public class getCurrentDayStock {

    public static DecimalFormat df = new DecimalFormat("#0.000");

    static SqlSession sqlSession = SqlSessionUtil.openSession();
    static StockMapper mapper = sqlSession.getMapper(StockMapper.class);
    private static ArrayList<Data> dataList = new ArrayList<Data>();

    public static List<Stock> getStcokList() {
        List<Stock> stocks = mapper.selectAllStock();
        JSONObject jsonObject = new JSONObject();

        for (Stock stock : stocks) {
            String code = stock.getCode();
            int type = stock.getType();
            jsonObject.put(code, type);

        }
        return stocks;
    }

    public static void main(String[] args) throws Exception {


        //ExecutorService executorService = Executors.newFixedThreadPool(50);
        //获取所有股票列表
        List<Stock> stcokList = getStcokList();
        for (Stock stock : stcokList) {
            //executorService.execute(() -> {
                try {
                    getDCData(stock.getCode(), stock.getType());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            //});
        }
        System.out.println(1254);
    }


    public static void getDCData(String code, int type) throws Exception {

        String data = getBDWebData(code, type);
        if (data == null) {
            return;
        }

        JSONObject jsonObject = JSONObject.parseObject(data);
        if (jsonObject.get("data") != null) {
            JSONObject jsonObject1 = JSONObject.parseObject(jsonObject.get("data").toString());
            String name = jsonObject1.get("name").toString();
            JSONArray klines = JSONArray.parse(jsonObject1.get("klines").toString());
            if (klines.size() > 120) {
                int i = 1;
                //昨日涨幅
                double v = Double.parseDouble(klines.get(klines.size() - i).toString().split(",")[8]);
                JSONObject lines = getLines(klines, i);
                double f1 = Double.parseDouble(lines.get("f1").toString());
                double te1 = Double.parseDouble(lines.get("te1").toString());
                double tw1 = Double.parseDouble(lines.get("tw1").toString());
                double th1 = Double.parseDouble(lines.get("th1").toString());
                double six1 = Double.parseDouble(lines.get("six1").toString());

                //开盘价
                double k = Double.parseDouble(klines.get(klines.size() - i).toString().split(",")[1]);
                //收盘价
                double s = Double.parseDouble(klines.get(klines.size() - i).toString().split(",")[2]);
                //最高价
                double g = Double.parseDouble(klines.get(klines.size() - i).toString().split(",")[3]);
                //最低价
                double d = Double.parseDouble(klines.get(klines.size() - i).toString().split(",")[4]);


                boolean bf = d < f1 && s > f1;
                boolean bte = d < te1 && s > te1;
                boolean btw = d < tw1 && s > tw1;
                boolean bth = d < th1 && s > th1;
                boolean bsix = d < six1 && s > six1;
                String word = "";
                int flag = 0;
                if (bf) {
                    word = word.concat("上穿五日线");
                    flag++;
                }
                if (bte) {
                    word = word.concat("上穿10日线");
                    flag++;
                }
                if (btw) {
                    word = word.concat("上穿20日线");
                    flag++;
                }
                if (bth) {
                    word = word.concat("上穿30日线");
                    flag++;
                }
                if (bsix) {
                    word = word.concat("上穿60日线");
                    flag++;
                }

                //收盘与最高差距
                double v0000 = (g - s) * 100 / k;
                boolean getPrice12010 = getPrice12010(klines, i, 120, 10);
                boolean getPrice12020 = getPrice12010(klines, i, 120, 20);
                boolean getPrice12030 = getPrice12010(klines, i, 120, 30);
                boolean moneyBL120110 = getMoney(klines, i, 120, 110);
                boolean moneyBL120100 = getMoney(klines, i, 120, 100);
                boolean moneyBL12090 = getMoney(klines, i, 120, 90);
                System.out.println(klines.size());
                if (v < 9.8 && v > 0) {
                    if (flag ==2) {
                        if (getPrice12010) {

                         /*   System.out.println("一年涨次 2603，跌次 2081，涨概率 55.7 %，平均涨 0.34，中股天：206");
                            System.out.println("三年涨次 6122，跌次 4770，涨概率 56.2 %，平均涨 0.34，中股天：499");*/
                            if (moneyBL120110) {
                                System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }else {

                                }
                            }
                            if (moneyBL120100) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }

                        }

                        if (getPrice12020) {

                            if (moneyBL120110) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL120100) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }

                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                        }

                        if (getPrice12030) {

                            if (moneyBL120110) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL120100) {
                                System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                        }

                    }
                    if (flag > 2) {
                        if (getPrice12010) {

                               /* System.out.println("一年涨次 53，跌次 30，涨概率 63.7 %，平均涨 0.9，中股天：31");
                                System.out.println("三年涨次 125，跌次 68，涨概率 64.7 %，平均涨 0.81，中股天：89");*/
                            if (moneyBL120110) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL120100) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }

                        }

                        if (getPrice12020) {

                            if (moneyBL120110) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL120100) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                        }

                        if (getPrice12030) {
                             System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                            if (moneyBL120110) {
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL120100) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                            if (moneyBL12090) {
                                 System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                                if (v0000 < 0.2) {

                                }
                            }
                        }

                        // System.out.println(name + " : " + klines.get(klines.size()-i).toString().split(",")[1] + "  当日涨幅" + v);
                    }
                }
            }
        }
    }




        }

